package top.fengyulou.code.controller.front.project;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import top.fengyulou.code.entity.Project;
import top.fengyulou.code.entity.ProjectForm;
import top.fengyulou.code.service.ProjectService;
import top.fengyulou.common.Jr;
import top.fengyulou.config.interceptor.ProjectInterceptor;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 不走登录拦截的链接
 */
@Controller
@RequestMapping("/f/project")
public class FrontProjectController {

    @Resource
    private ProjectService projectService;

    /**
     * 项目列表
     *
     * @return
     */
    @GetMapping("/list")
    public String list(Model model) {
        List<ProjectForm> list = projectService.getAll();
        model.addAttribute("list", list);
        return "front/project/front-project-list";
    }

    /**
     * 项目选择
     *
     * @return
     */
    @PostMapping("/choice")
    @ResponseBody
    public Jr choiceProject(HttpSession session, @RequestParam Long pId) {
        Project project = projectService.getById(pId);
        session.setAttribute(ProjectInterceptor.SELECT_PROJECT, project);
        return Jr.yes();
    }

}
